package com.ry.rabbitmq.receive;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DirectReceive {


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "directExQueue"),
            exchange = @Exchange(value = "directEx"),
            key = "x1"
    ))
	public void sendMessage(String msg, Message message, Channel channel) throws IOException {
		System.out.println("接到的消息 ： "+msg);
//		System.out.println(new String(message.getBody()));
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //手工ack，需要配置文件里做配置
        channel.basicAck(deliveryTag,true);
        System.out.println("receive--1: " + new String(message.getBody()));
	}
	
}
